package com.wangyu.talents.core.entity;

import java.util.Date;
import org.hibernate.validator.constraints.Length;

/**
 * 数据Entity 基类，对象创建信息
 *
 * @author wangyu
 * @Date 2018-09-02 9:30
 */
public abstract class DataEntity<T> extends BaseEntity<T> {

  private static final long serialVersionUID = -5534334957978812402L;

  protected Long created;    // 创建日期,时间戳
  protected Long modified;  // 更新日期，时间戳
  protected Long createdBy;  //创建人
  protected Long modifiedBy;  //修改人
  protected Integer deleted;  // 删除标记（0：正常；1：删除；2：审核）
  protected String remark;  // 备注

  public DataEntity() {
    super();
    this.deleted = DEL_FLAG_NORMAL;
  }

  public DataEntity(Long id) {
    super(id);
  }

  /**
   * 插入之前执行方法，需要手动调用
   */
  public void preInsert() {
    // 不限制ID为UUID，调用setIsNewRecord()使用自定义ID
    if (!this.isNewRecord) {
      //setId(IdGen.uuid());
    }
    this.created = System.currentTimeMillis() / 1000;
    this.modified = this.created;
  }

  /**
   * 更新之前执行方法，需要手动调用
   */
  public void preUpdate() {
    this.modified = System.currentTimeMillis() / 1000;
  }

  @Length(min = 0, max = 100)
  public String getRemark() {
    return remark;
  }

  public void setRemark(String remark) {
    this.remark = remark;
  }


  public void setCreateDate(Date createDate) {
    if (createDate != null) {
      this.created = createDate.getTime() / 1000;
    }
  }

  public void setCreated(Date created) {
    if (created != null) {
      this.created = created.getTime() / 1000;
    }
  }


  public Long getCreated() {
    return created;
  }

  public Long getModified() {
    return modified;
  }

  public void setModified(Long modified) {
    this.modified = modified;
  }

  public Long getCreatedBy() {
    return createdBy;
  }

  public void setCreatedBy(Long createdBy) {
    this.createdBy = createdBy;
  }

  public Long getModifiedBy() {
    return modifiedBy;
  }

  public void setModifiedBy(Long modifiedBy) {
    this.modifiedBy = modifiedBy;
  }

  public Integer getDeleted() {
    return deleted;
  }

  public void setDeleted(Integer deleted) {
    this.deleted = deleted;
  }

}
